<template>
  <div class="xtx-bread-item">
    <!-- 如果传递了to属性则可以点击 -->
    <template v-if="to">
      <router-link :to="to">
        <slot></slot>
      </router-link>
    </template>

    <!-- 如果没有传递to属性则不可以点击 -->
    <template v-else>
      <span>
        <slot />
      </span>
    </template>
    <i class="iconfont">{{ flag }}</i>
  </div>
</template>

<script>
import { inject } from 'vue'
export default {
  name: 'XtxBreadItem',
  props: {
    to: {
      tyep: String
    }
  },
  setup () {
    const flag = inject('key')

    return {
      flag
    }
  }
}
</script>
<style lang="less" scoped>
.xtx-bread-item {
  // 最后一个i隐藏
  &:nth-last-of-type(1) {
    i {
      display: none;
    }
  }

  a {
    color: #666;
    transition: all 0.4s;
    &:hover {
      color: @xtxColor;
    }
  }
}
</style>
